<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>两个栈实现一个队列</title>
</head>
<body>
    <script>
        let stack1 = [];
        let stack2 = [];
        function push(node){
            stack1.push(node)
        }

        function pop(){
            // debugger
            while(stack1.length>0){
                stack2.push(stack1.pop())
            }
            let value = stack2.pop();

            while(stack2.length>0){
                stack1.push(stack2.pop());
            }
            return value;
        }
        
        push(1)
        push(2)
        push(3)
        push(4)
        push(5)
        push(6)
        var num = pop();
        console.log(num);
        var num = pop();
        console.log(num);
        var num = pop();
        console.log(num);
        push(7)
        var num = pop();
        console.log(num);
    </script>
</body>
</html>